package com.hex.liyue.usermodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.usermodule.bean.MyWalletResultbean;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterWallet extends RecyclerView.Adapter<AdapterWallet.MyHolder> {
    private List<MyWalletResultbean.DataBean.RecordsBean> records;

    public void setRecords(List<MyWalletResultbean.DataBean.RecordsBean> records) {
        this.records = records;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_wallet, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        MyWalletResultbean.DataBean.RecordsBean recordsBean = records.get(position);
        holder.tv_transaction_time.setText(DateUtils.getFormatDate(recordsBean.transaction_time * 1000, "yyyy-MM-dd HH:mm:ss"));
        holder.tv_description.setText(recordsBean.description);
        holder.tv_tips.setText(recordsBean.tips);
        if (recordsBean.type.equals("1")) {
            //礼物折现
            holder.tv_transaction_price.setText("+ ￥" + recordsBean.transaction_price);
        } else if (recordsBean.type.equals("2")) {
            //余额提现成功
            holder.tv_transaction_price.setText("- ￥" + recordsBean.transaction_price);
        } else if (recordsBean.type.equals("3")) {
            //购买礼物
            holder.tv_transaction_price.setText("- ￥" + recordsBean.transaction_price);
        } else if (recordsBean.type.equals("4")) {
            //下线返现
            holder.tv_transaction_price.setText("+ ￥" + recordsBean.transaction_price);
        } else if (recordsBean.type.equals("5")) {
            //余额提现到银行卡中
            holder.tv_transaction_price.setText("- ￥" + recordsBean.transaction_price);
        } else if (recordsBean.type.equals("6")) {
            //余额提现失败
            holder.tv_transaction_price.setText("+ ￥" + recordsBean.transaction_price);
        }
    }

    @Override
    public int getItemCount() {
        if (records == null) {
            return 0;
        }
        return records.size();
    }


    class MyHolder extends RecyclerView.ViewHolder {
        TextView tv_transaction_price, tv_transaction_time, tv_description, tv_tips;

        public MyHolder(View itemView) {
            super(itemView);
            tv_transaction_price = (TextView) itemView.findViewById(R.id.tv_transaction_price);
            tv_transaction_time = (TextView) itemView.findViewById(R.id.tv_transaction_time);
            tv_description = (TextView) itemView.findViewById(R.id.tv_description);
            tv_tips = (TextView) itemView.findViewById(R.id.tv_tips);
        }

    }
}
